<template>
  <!-- -----供货商管理 ------ -->
  <div class="Suppliermanagement">
    <div class="search">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input v-model="search.key" placeholder="输入编号/供货商名称"></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="search.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onsubmit">查询</el-button>
        </el-form-item>
      </el-form>
      <el-button class="ebtn" type="primary" plain @click="GotoPg(null,null)">新增供货商</el-button>
    </div>
    <el-table :data="ListData"  style="margin: 10px 20px;width: calc( 100% - 40px)" :height="autoHeightTable"
              show-overflow-tooltip>
      <el-table-column prop="xuhao" type="index" label="序号" width="100" align="center"/>
      <el-table-column prop="enterpriseNumber" label="编号" align="center"/>
      <el-table-column prop="enterpriseName" label="供货商名称" align="center"/>
      <el-table-column prop="contacts" label="联系人" align="center"/>
      <el-table-column prop="contactsPhone" label="联系方式" align="center"/>
      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button size="small" type="warning"  @click="GotoPg(scope.row.id,2)">结算</el-button>
          <el-button size="small" type="primary"  @click="GotoPg(scope.row.id,null)">编辑</el-button>
          <el-button type="text" size="small" @click="GotoPg(scope.row.id,1)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="current"
      :page-size="pagesize"
      @current-change="handleCurrentChange"
      :page-count="total">
    </el-pagination>
  </div>
</template>

<script>
import axios from "axios";

export default {
  computed: {
    autoHeightTable() {
      return document.documentElement.scrollHeight - 251 - 78;
    }
  },
  data() {
    return {
      search: {key: "", start: "", end: ""},
      ListData: [],
      total: 1,
      current: 1,
      pagesize: 10,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleCurrentChange(e) {
      this.current = e;
      this.getList();
    },
    /*列表页数据获取*/
    getList(){
      const message= JSON.parse(localStorage.getItem("message"));
      const pageRequest={
        "beginTime": this.search.start,
        "cunfangAddress": "",
        "did": 0,
        "endTime": this.search.end,
        "key": this.search.key,
        "pageNum": this.current,
        "pageSize": this.pagesize,
        "rid": 0,
        "type": 0
      }
      axios.post("/JX_java/procurement/supplier/getSupplierList?userId="+message.Id,pageRequest).then(res=>{
        console.log(res.data.data,"数据");
        this.ListData=res.data.data.content;
        this.total=res.data.data.totalSize
      })
    },
    LoadCount() {
      let jsondata = {
        pageNum: 0,
        pageSize: 0,
        key: this.search.key,
        beginTime: this.search.start,
        endTime: this.search.end,
        rid: 0,
        type: 0,
        cunfangAddress:""
      }
    const userId= JSON.parse(localStorage.getItem("message")).Id;
      axios.post("/JX_java/procurement/supplier/getSupplierList?userId="+userId,jsondata).then(res=>{
        console.log(res,"后台地址")

      })

    },
    LoadContents() {
      let jsondata = {
        pageNum: 0,
        pageSize: 0,
        key: this.search.key,
        beginTime: this.search.start,
        endTime: this.search.end,
        rid: 0,
        type: 0,
        cunfangAddress:""
      }
     /* let jsondata_str = JSON.stringify(jsondata)
      console.log(jsondata_str)
      axios("/apis/ScSaiGouMamage.asmx/LoadContents?index=" + 1 + "&jsondata=" + jsondata_str).then(({data}) => {
        var datas = this.$x2js.xml2js(data);
        var result = JSON.parse(datas.string.__text);
        this.ListData = result;
        console.log(result)
      });*/
    },
    onsubmit() {
      this.getList();
    },

    chage(e) {
      if (e) {
        this.search.start = e[0];
        this.search.end = e[1];
      } else {
        this.search.start = '';
        this.search.end = '';
      }
    },
    GotoPg(id, edit) {
      if (edit == 2) {
        this.$router.push({path: "./SettlementDetail", query: {id: id}});
      } else {
        this.$router.push({path: "./Newsupply", query: {id: id, edit: edit}});
      }
    },
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";

.Suppliermanagement .search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
  margin: 0 20px 20px;
}

.Suppliermanagement .demo-form-inline {
  display: inline-block;
}

.Suppliermanagement .el-pagination {
  margin-top: 15px;
  text-align: center;
}

.Suppliermanagement .ebtn {
  float: right;
  margin-right: 20px;
}
</style>
